package com.atguigu.tingshu.account.api;

import com.alibaba.fastjson.JSON;
import com.atguigu.tingshu.account.service.UserAccountService;
import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.account.UserAccountDetail;
import com.atguigu.tingshu.vo.account.AccountLockResultVo;
import com.atguigu.tingshu.vo.account.AccountLockVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Tag(name = "用户账户管理")
@RestController
@RequestMapping("api/account/userAccount")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserAccountApiController {


	private final UserAccountService userAccountService;
	
	@Autowired
	public UserAccountApiController(UserAccountService userAccountService) {
		this.userAccountService = userAccountService;
	}
	/**
	 * @description: 获取账号可用金额
	 * @author Petrichor 
	 * @date 2024/1/7 23:00
	 * @return 登录用户 账号可用金额
	**/
	@GuiGuLogin
	@Operation(summary = "获取账号可用金额")
	@GetMapping("/getAvailableAmount")
	public Result<BigDecimal> getAvailableAmount() {
		return Result.ok(userAccountService.getAvailableAmount());
	}

	/**
	 * @description: 检查并锁定可用余额
	 * @author Petrichor
	 * @date 2024/1/8 19:47
	 * @param accountLockVo 锁定金额对象
	 * @return AccountLockResultVo 锁定金额返回对象
	**/
	@GuiGuLogin
	@PostMapping(value = "/checkAndLock")
	public Result<AccountLockResultVo> checkAndLock(@RequestBody AccountLockVo accountLockVo){
		AccountLockResultVo accountLockResultVo = userAccountService.checkAndLock(accountLockVo);

		return Result.ok(accountLockResultVo);
	}
	/**
	 * @description: 获取用户充值记录
	 * @author Petrichor
	 * @date 2024/1/11 11:45
	 * @param page 当前页码
	 * @param limit 每页记录数
	 * @return 当前登录用户的充值记录
	**/
	@GuiGuLogin
	@Operation(summary = "获取用户充值记录")
	@GetMapping("/findUserRechargePage/{page}/{limit}")
	public Result<IPage<UserAccountDetail>> findUserRechargePage(
			@Parameter(name = "page", description = "当前页码", required = true)
			@PathVariable Long page,
			@Parameter(name = "limit", description = "每页记录数", required = true)
			@PathVariable Long limit) {
		Long tradeType = 1201L;
		IPage<UserAccountDetail> pageModel = userAccountService.findUserTradeTypePage(page , limit,tradeType);
		return Result.ok(pageModel);
	}
	/**
	 * @description: 获取用户消费记录
	 * @author Petrichor
	 * @date 2024/1/11 11:58
	 * @param page 当前页码
	 * @param limit 每页记录数
	 * @return
	**/
	@GuiGuLogin
	@Operation(summary = "获取用户消费记录")
	@GetMapping("findUserConsumePage/{page}/{limit}")
	public Result<IPage<UserAccountDetail>> findUserConsumePage(
			@Parameter(name = "page", description = "当前页码", required = true)
			@PathVariable Long page,
			@Parameter(name = "limit", description = "每页记录数", required = true)
			@PathVariable Long limit) {
		Long tradeType = 1204L;
		IPage<UserAccountDetail> pageModel = userAccountService.findUserTradeTypePage(page, limit,tradeType);
		return Result.ok(pageModel);
	}
}

